package lianxi01;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86131
 * Date: 2024-04-21
 * Time: 13:01
 */
public class MyThread extends Thread{
    static int ticket = 0;
    static Object obj = new Object();  //锁对象

    @Override
    public void run() {
        while(true) {
            synchronized (MyThread.class) {
                if(ticket < 1000) {
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    ticket++;
                    System.out.println(getName()+"正在卖第"+ticket+"张票!!!");

                }else {
                    break;
                }
            }
        }
    }
}
